<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>个人基金小助手</title>
    <link rel="stylesheet" href="css/layui.css?t=1615823099769" media="all">
    <style>
        body {
            margin: 10px;
        }

        .demo-carousel {
            height: 200px;
            line-height: 200px;
            text-align: center;
        }

        .layui-form-label {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 94px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
        }

        .layui-input, .layui-textarea {
            display: block;
            width: 500px;
            padding-left: 10px;
        }

        .testBack {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            min-width: 1000px;
            z-index: -10;
            zoom: 1;
            background-color: #fff;
            /*background: url(1.jpg);*/
            background-repeat: no-repeat;
            background-size: cover;
            -webkit-background-size: cover;
            -o-background-size: cover;
            background-position: center 0;
        }
    </style>
    <script src="jquery-3.5.1.min.js"></script>
</head>
<body>
<div style="margin: inherit">
    <ul class="layui-nav">
        <li class="layui-nav-item">
            <a href="javascript:logout()">退出登录</a>
        </li>
        <li class="layui-nav-item">
            <a href="">个人中心</a>
        </li>
        <li class="layui-nav-item" lay-unselect="">
            <a href="javascript:;"><img src="//t.cn/RCzsdCq" class="layui-nav-img">我</a>
            <dl class="layui-nav-child">
                <dd><a href="javascript:registered();">注册用户</a></dd>
                <dd><a href="javascript:changepwd();">修改密码</a></dd>
                <!--            <dd><a href="javascript:;">退了</a></dd>-->
            </dl>
        </li>
    </ul>
</div>


<!--<div class="layui-fluid">

    <div class="layui-row">
        <div class="layui-col-sm3">
            <div class="grid-demo grid-demo-bg1"><img src="1.gif"></div>
        </div>
        <div class="layui-col-sm3">
            <div class="grid-demo"><img src="1.gif"></div>
        </div>
        <div class="layui-col-sm3">
            <div class="grid-demo grid-demo-bg1"><img src="1.gif"></div>
        </div>
        <div class="layui-col-sm3">
            <div class="grid-demo"><img src="1.gif"></div>
        </div>
    </div>
</div>-->
<hr>

<blockquote class="layui-elem-quote">韭菜工具-每日补仓计算</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>使用说明:</legend>
</fieldset>
<blockquote class="layui-elem-quote layui-quote-nm">
    输入本金,和累计负收益率,和预期收入,然后就可以计算出你当天需要补仓多少
    <br>第二天系统预设是涨3个点,计算补仓
</blockquote>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<div>
    <form class="layui-form" action="" lay-filter="example">
        <div class="layui-form-item">
            <label class="layui-form-label">基金产品名称</label>
            <div class="layui-input-inline " id="selectFuno" >
                <select name="productName" lay-verify="required" lay-search="" id="currency"  lay-filter="choose">
                    <option value="">请输入或选择基金产品</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">本金</label>
            <div class="layui-input-block">
                <input type="text" name="principal" lay-verify="number" placeholder="请输入本金" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">当天收益率(%)</label>
            <div class="layui-input-block">
                <input  id="gszzl" type="text" name="plrate" lay-verify="plrate" placeholder="请输入累计收益率(亏损就输入-0.0x)"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">预期收益目标</label>
            <div class="layui-input-block">
                <input type="text" name="expectMoney" lay-verify="number" placeholder="请输入预期收益目标" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <!--                <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-setval">赋值</button>-->
                <!--                <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-getval">取值</button>-->
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>

<hr>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>补仓列表</legend>
</fieldset>
<table class="layui-hide" id="demo" lay-filter="test"></table>


<script src="layui.js?t=1615823099769"></script>
<script>
    layui.config({
        version: '1615823099769' //为了更新 js 缓存，可忽略
    });

    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider', 'form', 'layedit', 'laydate'], function () {
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
            , layer = layui.layer //弹层
            , table = layui.table //表格
            , carousel = layui.carousel //轮播
            , upload = layui.upload //上传
            , element = layui.element //元素操作
            , slider = layui.slider //滑块
            , form = layui.form
            , layedit = layui.layedit;


        //监听Tab切换
        element.on('tab(demo)', function (data) {
            layer.tips('切换了 ' + data.index + '：' + this.innerHTML, this, {
                tips: 1
            });
        });
        getSelect();

        //执行一个 table 实例
        table.render({
            elem: '#demo'
            , height: 420
            , url: '/list' //数据接口
            , title: '基金表'
            , page: true //开启分页
            , toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , totalRow: false //开启合计行
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'xuhao', title: '序号', width: 100, sort: true,templet:'#xuhao'}
                // , {field: 'id', title: 'ID', width: 60, sort: true, totalRowText: '合计：'}
                , {field: 'productName', title: '产品名称', width: 200}
                , {field: 'principal', title: '本金',sort: true, width: 100}
                , {field: 'plrateStr', title: '当日盈亏率', width: 150, sort: true, templet: '#sexTpl'}
                , {field: 'loseMoney', title: '已亏损/盈利金额', width: 150, sort: true, templet: '#moneyTpl'}
                , {field: 'expectMoney', title: '期望盈利百分比或金额', width: 150, sort: true}
                , {
                    field: 'repairMoney',
                    title: '补仓金额',
                    width: 150,
                    sort: true,
                    totalRow: true,
                    style: 'background-color: #009688; color: #fff;'
                }
                , {field: 'tomorrMoney', title: '第二天卖出手续费', width: 150, sort: true, totalRow: true}
                , {field: 'createTime', title: '日期', width: 200}
                , {field: 'createor', title: '创建人', width: 150}
                , {fixed: 'right', width: 200, title: '操作', align: 'center', toolbar: '#barDemo'}
            ]],
            id: 'testReload'
        });




        //监听头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    layer.msg('添加');
                    layer.open()
                    break;
                case 'update':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length > 1) {
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.alert('编辑 [id]：' + checkStatus.data[0].id);
                    }
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {
                        const list = data.map(item => (item.id))
                        console.log(list);
                        $.ajax({
                            type: 'POST',
                            url: '/delAll',//发送请求
                            data: JSON.stringify(list),
                            dataType: "json",
                            contentType: 'application/json; charset=utf-8',
                            success: function (result) {
                                var htmlCont = result;//返回的结果页面

                                if (result.code == 0) {
                                    layer.msg(result.message,{icon: 1});
                                    //执行重载
                                    table.reload('testReload', {
                                        page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    }, data);

                                } else {
                                    layer.msg("操作失败",{icon: 5});
                                }
                            }
                        });
                    }
                    break;
            }
            ;
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                layer.msg('查看操作');
            } else if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    console.log(obj)
                    // obj.del(); //删除对应行（tr）的DOM结构
                    // layer.close(index);
                    $.ajax({
                        type: 'POST',
                        url: '/del',//发送请求
                        data: {id: data.id},
                        dataType: "json",
                        success: function (result) {
                            var htmlCont = result;//返回的结果页面

                            if (result.code == 0) {
                                layer.msg(result.message,{icon: 1});
                                //执行重载
                                table.reload('testReload', {
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                }, data);

                            } else {
                                layer.msg("操作失败",{icon: 5});
                            }
                        }
                    });

                });

            } else if (layEvent === 'edit') {
                layer.msg('编辑操作');
            }
        });

        //执行一个轮播实例
        carousel.render({
            elem: '#test1'
            , width: '100%' //设置容器宽度
            , height: 200
            , arrow: 'none' //不显示箭头
            , anim: 'fade' //切换动画方式
        });

        //将日期直接嵌套在指定容器中
        var dateIns = laydate.render({
            elem: '#laydateDemo'
            , position: 'static'
            , calendar: true //是否开启公历重要节日
            , mark: { //标记重要日子
                '0-10-14': '生日'
                , '2020-01-18': '小年'
                , '2020-01-24': '除夕'
                , '2020-01-25': '春节'
                , '2020-02-01': '上班'
            }
            , done: function (value, date, endDate) {
                if (date.year == 2017 && date.month == 11 && date.date == 30) {
                    dateIns.hint('一不小心就月底了呢');
                }
            }
            , change: function (value, date, endDate) {
                layer.msg(value)
            }
        });

        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            , count: 100 //总页数
            , skin: '#1E9FFF' //自定义选中色值
            //,skip: true //开启跳页
            , jump: function (obj, first) {
                if (!first) {
                    layer.msg('第' + obj.curr + '页', {offset: 'b'});
                }
            }
        });


        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
            , plrate: function (value) {
                // var reg = new RegExp("^(0|-0).[0-9]*$");
                var reg = new RegExp("^[0-9\-\.]*$");
                if (!reg.test(value)) {
                    return '请输入小数啊';
                }
            },
            number: function (value) {
                var reg = new RegExp("^[0-9]*$");
                if (!reg.test(value)) {
                    return '请输入小数啊';
                }
            }

        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });


        form.on('select(choose)', function(data) {

            var value = data.value;
            console.log("11111111111")
            console.log(value)
            $.ajax({
                url:'/queryFundForCode',
                type:'post',
                data:JSON.stringify({"fundcode":value}),
                dataType:'json',
                contentType: 'application/json; charset=utf-8',
                success:function(data){
                    console.log(data)
                    if(data.code==0){
                        var gszzl= data.data.gszzl.toString();
                        console.log("gszzzzzzzzzl",gszzl);
                        $("#gszzl").val(gszzl);

                    }

                }
            });
            if(value == 0) {
                $("#count").attr("style", ""); //设置为可见
            } else {
                $("#count").attr("style", "display:none;"); //设置为隐藏
            }
        });



        //获取基金下拉
        function getSelect() {

            var src='<option value="">请输入或选择基金产品名称</option>';
            $.ajax({
                url:'/queryFundInfo',
                type:'post',
                data:JSON.stringify({}),
                dataType:'json',
                contentType: 'application/json; charset=utf-8',
                success:function(data){
                    console.log(data)
                    if(data.code==0){

                        $.each(data.data,function(index,item){
                            src+='<option  value="'+item.name+'-'+item.fundCode+'">'+item.name+'-'+item.fundCode+'</option>';
                        });
                        $('#currency').html(src);
                        form.render();
                    }

                }
            });

        }

        //监听提交
        form.on('submit(demo1)', function (data) {
            $.ajax({
                type: 'POST',
                url: '/add',//发送请求
                data: JSON.stringify(data.field),
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                success: function (result) {
                    var htmlCont = result;//返回的结果页面

                    if (result.code == 0) {
                        layer.msg(result.message,{icon: 1});
                        //执行重载
                        table.reload('testReload', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        }, data);

                    } else {
                        layer.msg("新增失败", {icon: 5});
                    }
                }
            });


            return false;
        });

        //表单赋值
        layui.$('#LAY-component-form-setval').on('click', function () {
            form.val('example', {
                "username": "贤心" // "name": "value"
                , "password": "123456"
                , "interest": 1
                , "like[write]": true //复选框选中状态
                , "close": true //开关状态
                , "sex": "女"
                , "desc": "我爱 layui"
            });
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });
    });

    //退出登录
    function logout() {
        $.ajax({
            type: 'POST',
            url: '/logout',//发送请求
            data: {},
            dataType: "json",
            contentType: 'application/json; charset=utf-8',
            success: function (result) {
                var htmlCont = result;//返回的结果页面

                if (result.code == 0) {
                    layer.msg(result.message,{icon: 1});
                    //执行重载

                } else {
                    layer.msg(result.message, {icon: 5});
                }
            }
        });
        top.location = '/page/login/index.html';

    }

    //注册用户
    function registered() {
        layer.open({
            type: 2,
            content: 'createUser.html',
            area: ['600px', '300px'],
            title: '注册用户'
        });

    }



    //修改密码
    function changepwd() {
        layer.open({
            type: 2,
            content: 'updateUser.html',
            area: ['600px', '300px'],
            title: '修改密码'
        });
    }


</script>
<script type="text/html" id="sexTpl">
    {{#  if(d.plrateStr.indexOf("-") != -1){
    }}
    <span style="color:green;">{{ d.plrateStr }}</span>
    {{#  } else { }}
    <span style="color:red;">{{ d.plrateStr }}</span>

    {{#  } }}
</script>
<script type="text/html" id="moneyTpl">
    {{#  if(d.loseMoney.toString().indexOf("-") != -1){
    }}
    <span style="color:green;">{{ d.loseMoney }}</span>
    {{#  } else { }}
    <span style="color:red;">{{ d.loseMoney }}</span>

    {{#  } }}
</script>
<script type="text/html" id="xuhao">
     {{d.LAY_TABLE_INDEX+1}}
</script>
<script>
    $(function () {
        /*公共部分
         * 导航栏
         * footer CopyRight
         */
        $(".headerpage").load("head.html");
        $(".footerpage").load("footer.html");
    });
</script>


</body>
</html>
        